﻿using System;
using MailClient;
using MailClient.Data;
using MailClient.Handlers;

namespace MailClient.Commands
{
    /// <summary>
    /// Responds to the sender with a list and description of all commands available
    /// </summary>
    class help : ICommand, IDisposable
    {
        #region Private
        private MailMessage _msg;
        private Handlers.Command _parameter;
        private Handlers.designator _designator;
        #endregion

        #region CTOR
        public help(Command com) { _parameter = com; }
        #endregion

        #region Public
        public Handlers.designator Designator
        {
            get { return _designator; }
            set { _designator = Designator; }
        }

        public MailMessage MsgReply
        {
            get { return _msg; }
        }

        public void Dispose() { }

        public bool CommitData() { return false; }

        public bool Command(Job job)
        {
            string preamble = "";
            string commandlist = "";

            switch (_parameter)
            {
                default:
                    preamble = "\nReply to this email with one of the following commands" +
                           " in the subject line. Some commands require a Store name or number" +
                           " inorder to be useful. \nTypical usage of any command is \"Command\" Store name or number\n";

                    commandlist = "\n<ul><li><b>Help</b> - returns this message.  Help Command - returns detailed help on a given command.</li>\n" +
                        "\n<li><b>Approval</b> - Used by persons with appropriate permissions to approve specific actions.</li>\n" +
                        "\n<li><b>Contacts</b> <i>Store Name</i> or <i>Number</i> - returns a current list of all contact on file for a given store.</li>\n" +
                        "\n<li><b>Info</b> <i>Store Name</i> or <i>Number</i> - Use to get information regarding projects, contacts, project contacts, schedules, etc." +
                        " Info returns detailed information.  It is recommended to use a more appropriate command if you just want specific information.</li>\n" +
                        "\n<li><b>List</b> <i>Store Name</i> or <i>Number</i> - returns current project status and schedule.</li>\n" +
                        "\n<li><b>Stop</b> <i>Store Name</i> or <i>Number</i> - stops the email notifications on a particular store but does not remove you from the distribution list for the store.</li>\n" +
                        "\n<li><b>Subscribe</b> <i>Store Name</i> or <i>Number</i> - Adds you to the distribution list for a particular store.</li>\n" +
                        "\n<li><b>Unsubscribe</b> <i>Store Name</i> or <i>Number</i> - Removes you from the distribution list for a particular store.\n</li></ul>";
                    break;
                case Handlers.Command.Approval:
                    preamble = @"
Allows for the approval of people to specific projects or lists and sets or removes approval constraints on projects.
You need to have appropriate permissions for this command to be effective.  Used with the prefix ""Requires"" it will set the requires approval flag.
To remove approvals or requires approval flag send command prefixed with ""-"".  you can add or take away approvals on multiple jobs or people just list them out with a comma separator.
    example:  ""<b>Requires Approval</b> <i>Somejob, Somejob2, Somejob3</i>""  adds the flag
              ""<b>-Requires Approval</b> <i>Somejob</i>"" removes the flag
              ""<b>Approve</b> <i>Someone Somejob</i>"" gives approval for a person to a particular job
              ""<b>-Approve</b> <i>Someone Somejob</i>"" takes away approval for a person on a particular job
              ""<b>Approve</b> <i>Someone Somejob, Somejob2, Somejob3</i>"" 
You can also approve someone for all jobs or for a certain project type.
    example:  ""<b>Approve</b> <i>Someone Alljobs</i>"" This is everything, be careful
              ""<b>Approve</b> <i>Someone Takeovers</i>"" just takeover jobs
              ""<b>Approve</b> <i>Someone Takeovers, Relos</i>"" you can assign multiple types just separate each with a comma
The - prefix in front of any of these commands reverses and undoes the approval grants";

                    commandlist = @"

<b>Approve</b> <i>'job or person' 'arguments'</i>
arguments maybe any or all of the following:
    Job Types:
        <b>Alljobs</b>
        <b>Takeovers</b>
        <b>Relos</b>
        <b>New</b>
        <b>Expansions</b>";
                    break;
                case Handlers.Command.Contacts:
                    preamble = @"
<b>Contacts</b> <i>Somejob</i> or <i>Someone</i> returns the contact or contacts that we have on file.  The information is as accurate as we can make it.
If you do notice an error or an omission please reply to this email or forward the email to <a href=""mailto:amills@rhaaia.com"">amills@rhaaia.com</a>.
";

                    commandlist =string.Format( @"
<b>Contact</b> <i>'arguments' 'job or person'</i>
<b>Contact</b> <i>Store Name</i> or <i>Number</i> - returns a current list of all contact on file for a given store.
<b>Contact</b> <i>Some person</i> - returns a current list of all jobs this person is associated with.
<b>Contact</b> <i>Job type</i> - returns all contacts based on the job type.  
    Job Types:
        <ul>
        <li><b>Alljobs</b></li>
        <li><b>Takeovers</b></li>
        <li><b>Relos</b></li>
        <li><b>New</b></li>
        <li><b>Expansions</b></li>
        </ul>

ARGUMENTS
<b>List</b> creates a simple list - this is the default
<b>Table</b> creates a table view

Example: if you send 'Contacts Jerry Actric'
you will see something like this:
<TABLE border=""0"" cellpadding=""1"">
                                <TR>
                                    <TD bgcolor=""#FFFFFF"" align=""center"" width=""500"" valign=""middle"">
                                        <TABLE border=""0"" cols=""2"" style=""font-size: 9pt; color: black; font-family: verdana, helvetica"" width=""100%"" cellspacing=""2"" cellpadding=""0"">
                    <TR id=""{0}"">
                        <TD valign=""top"" bgcolor=""#FFFFFF"" align=""right"">
                          <DIV id=""{0}"" style=""font-weight:bold"">
                            <NOBR>{0}</NOBR>
                          </DIV>
                        </TD>
                        <TD>&nbsp;&nbsp;&nbsp;</TD>
                        <TD valign=""top"">
                          {1}
                        </TD>
                      </TR>
<TR id=""{2}"">
                        <TD valign=""top"" bgcolor=""#FFFFFF"" align=""right"">
                          <DIV id=""{2}"" style=""font-weight:bold"">
                            <NOBR>{2}</NOBR>
                          </DIV>
                        </TD>
                        <TD>&nbsp;&nbsp;&nbsp;</TD>
                        <TD valign=""top"">
                          {3}
                        </TD>
                      </TR>
<TR id=""{4}"">
                        <TD valign=""top"" bgcolor=""#FFFFFF"" align=""right"">
                          <DIV id=""{4}"" style=""font-weight:bold"">
                            <NOBR>{4}</NOBR>
                          </DIV>
                        </TD>
                        <TD>&nbsp;&nbsp;&nbsp;</TD>
                        <TD valign=""top"">
                          {5}
                        </TD>
                      </TR>", "first_name", "Jerry", "last_name", "Harry", "direct_phone", "555-555-5555");
                    break;
                case Handlers.Command.Info:
                    preamble = @"
<b>Info</b> <i>Store Name</i> or <i>Number</i> - Use to get specific information regarding projects and contacts.
";

                    commandlist = @"
<b>Info</b> <i>'job or person' 'arguments'</i>
<b>Info</b> <i>Store Name</i> or <i>Number</i> - returns a current list of all Info on file for a given store.
<b>Info</b> <i>Some person</i> - returns company info, job roles, and pertinent info.
<b>Info</b> <i>Job type</i> - returns all Info based on the job type.  
    Job Types:
        <b>Alljobs</b>
        <b>Takeovers</b>
        <b>Relos</b>
        <b>New</b>
        <b>Expansions</b>

ARGUMENTS
<b>List</b> creates a simple list
<b>Table</b> creates a table view
";

                    break;
                case Handlers.Command.List:
                     preamble = @"
<b>List</b> <i>Store Name</i> or <i>Number</i> - Use to get detailed information regarding projects and contacts.
List is generally a combination of the Contacts and Info commands.
";

                    commandlist = @"
<b>Info</b> <i>'job or person' 'arguments'</i>
<b>Info</b> <i>Store Name</i> or <i>Number</i> - returns a current list of all contacts and dates on file for a given store.
<b>Info</b> <i>Some person</i> - returns company info, job roles, and stores this person is working on.
<b>Info</b> <i>Job type</i> - returns all Info based on the job type.  
    Job Types:
        <b>Alljobs</b>
        <b>Takeovers</b>
        <b>Relos</b>
        <b>New</b>
        <b>Expansions</b>

ARGUMENTS
<b>List</b> creates a simple list
<b>Table</b> creates a table view
";
                    break;
                case Handlers.Command.Stop:

                    break;
                case Handlers.Command.Subscribe:

                    break;
                case Handlers.Command.Unsubscribe:

                    break;
            }
            _msg = new MailMessage();
            _msg.IsBodyHtml = true;
            _msg.Subject = "Response to your Help request";
            _msg.Body = preamble + commandlist;
            var from = new System.Net.Mail.MailAddress("rha@rhaaia.com", "RHA Email");
            _msg.To.Add(job.ReplyTo);
            _msg.Sender = from;
            return true;
        }
        #endregion



    }
}
